package com.nian.common.model;

import java.io.*;

/**
 * 用途：
 * 开发：zhangmj
 * 日期：2020/4/4 0004 17:29
 */
public class SerializeUtils {
    public static String serialize(Object obj) {
        try{
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            ObjectOutputStream objectOutputStream;
            objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
            objectOutputStream.writeObject(obj);
            String string = byteArrayOutputStream.toString("ISO-8859-1");
            objectOutputStream.close();
            byteArrayOutputStream.close();
            return string;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;

    }
    public static Object serializeToObject(String str) {
        try{
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(str.getBytes("ISO-8859-1"));
            ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
            Object object = objectInputStream.readObject();
            objectInputStream.close();
            byteArrayInputStream.close();
            return object;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

}
